<?php

/**
 * @author thihien
 * @copyright 2011
 */
require_once('includes/general.php');
if(!tep_db_checkDb()) die('khong ket noi dc csdl');
//chi tiet san pham
if(isset($_GET['mode']) && $_GET['mode']=='detail'){
$madanhmuc=$_GET['madanhmucsp'];
$masp=$_GET['masp'];
$sql='select * from sanpham where id='.$masp;
$kq=tep_db_query($sql);

$content='
    <div id="center">
        <div id="tt_sanpham">
            <div class="title"><h3>products</h3></div>';
        while($item=tep_db_fetch_array($kq)){
            $content.='
             
            
            <div id=noidung1>
                <div id="sanpham">
                    <div id="hinhanh1"><img  height="200" src="admin/upload/'.$item['hinhanh'].'"/></div>
                </div>
                <div id="tensp2">'.$item['tensanpham'].'</div>
                <div id="gia1" style="color: red;" > Your Price:$'.$item['gia'].'.00</div>
                <div id="noidungchitiet1">'.$item['motachitiet'].'</div>
            </div>
                
                ';
                
        }

$content.='
        </div>
        <div id="sanphamcungloai">
        
            <div id="tt_sanpham">
            <div class="title"><h3>same products</h3></div>';
            $sql='SELECT count(id) as count FROM `sanpham` where id!='.$masp.' and madanhmuc='.$madanhmuc;
            $kq=tep_db_query($sql);
            $item1=tep_db_fetch_array($kq);
            //bat dau viet phan trang
            $display=2;// so san pham xuat hien tren mot trang
            $record=$item1['count'];//tong so san pham
            if($record>$display){
                $page=ceil($record/$display);
            }
            else{
                $page=1;
            }
            $start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;
            $sql4='select * from sanpham where id!='.$masp.' and madanhmuc='.$madanhmuc.' limit '.$start.', '.$display.'';
            $kq4=tep_db_query($sql4);
            while($item1=tep_db_fetch_array($kq4)){
            $content.='
             
            <div id="sanpham">
                <div id="hinhanh1"><a href="?masp='.$item1['id'].'&madanhmucsp='.$item1['madanhmuc'].'&mode=detail"><img height="120"  src="admin/upload/'.$item1['hinhanh'].'"/></a></div>   
                <div id="tensp1">'.$item1['tensanpham'].'</div>
                <div id="gia1" style="color: red;" > Your Price:$'.$item1['gia'].'.00</div>
                <div><a href="?masp='.$item['id'].'&madanhmucsp='.$item1['madanhmuc'].'&mode=detail">detail...</a></div>
            </div>
                
                ';
                
        }
$content.='
         <ul id="phantrang">';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
                if($current!=1){
                   $content.='<li><a href="?mode=detail&start='.$prev.'">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                    if($current!=$i){
                        $content.='<li><a href="?mode=detail&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="?mode=detail&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    }
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="?mode=detail&start='.$next.'">Next</a></li>';  
                }
            }
            else{
                $content.='<li class="current"><a href="?page=sanpham&start='.$page.'">'.$page.'</a></li>';  
            }
       $content.=' </ul>
        </div>
        </div>
       
    </div> 
';
}
echo $content;
?>

